package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> point=new ArrayList<>();
        point.add(new Point(1,2));
        point.add(new Point(22,35));
        point.add(new Point(63,44));
        point.add(new Point(4,5));
        point.add(new Point(95,666));
        System.out.println("原始:"+point);

        Collections.sort(point, (o1, o2)-> {
                int len1=o1.getX()*o1.getX()+o1.getY()*o2.getY();
                int len2=o2.getY()*o2.getY()+o2.getX()*o1.getX();;
                return len1-len2;
            }
        );
        System.out.println("排序后:"+point);

        Collections.sort(point,(o1,o2)->{
            int len1=o1.getX()*o1.getX()+o1.getY()*o2.getY();
            int len2=o2.getY()*o2.getY()+o2.getX()*o1.getX();;
            return len1-len2;
        });
        System.out.println("优化后:"+point);
    }
}
